//
//  HomeHotOrderTableViewCell.m
//  GLGW_Shoping
//
//  Created by yang on 2018/11/30.
//  Copyright © 2018年 yang. All rights reserved.
//

#import "HomeHotOrderTableViewCell.h"

@interface HomeHotOrderTableViewCell ()
@property (nonatomic, strong) GLGWLabel *goodsLabel;
@property (nonatomic, strong) GLGWLabel *stellOLabel;
@property (nonatomic, strong) GLGWLabel *depositLabel;
@property (nonatomic, strong) GLGWLabel *baoJiaeLabel;

@property (nonatomic, strong) GLGWImageView *typeImageView;
@property (nonatomic, strong) MASConstraint *lableTopConstraint;

@end

@implementation HomeHotOrderTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        GLGWView *bankgroundView = [[GLGWView alloc] initWithInSuperView:self.contentView];
        bankgroundView.backgroundColor = [UIColor whiteColor];
        [bankgroundView setViewShadowWidth:3.0 theCornerRadius:3.0];
        [bankgroundView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.contentView.mas_left).offset(kWidthProportion_In_iPhoneTriploid(15));
            make.right.equalTo(self.contentView.mas_right).offset(-kWidthProportion_In_iPhoneTriploid(15));
            make.top.equalTo(self.contentView.mas_top).offset(kHeightProportion_In_iPhoneTriploid(10));
            make.bottom.equalTo(self.contentView.mas_bottom).offset(-kHeightProportion_In_iPhoneTriploid(10));
        }];
        self.typeImageView = [[GLGWImageView alloc] initInSuperView:bankgroundView];
        [self.typeImageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.top.equalTo(bankgroundView);
            make.width.equalTo(@(kWidthProportion_In_iPhoneTriploid(40)));
            make.height.equalTo(@(kHeightProportion_In_iPhoneTriploid(40)));
        }];
        //
        self.goodsLabel = [[GLGWLabel alloc] initWithFont:SYSTEMFONT(16) theColor:kColor_Rule_Black inSuperView:bankgroundView];
        self.goodsLabel.numberOfLines = 0;
//        self.goodsLabel.text = @"碳钢弯头 Q235 70*20*40 1件 / 热镀锌钢管 Q235 70*20*40 1件 / 碳钢弯头 Q235 70… / 碳钢弯头 Q235 70… / 碳钢弯头 Q235 70…";
        [self.goodsLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(bankgroundView.mas_left).offset(kWidthProportion_In_iPhoneTriploid(20));
            make.top.equalTo(bankgroundView.mas_top).offset(kHeightProportion_In_iPhoneTriploid(18));
            make.right.equalTo(bankgroundView.mas_right).offset(-kWidthProportion_In_iPhoneTriploid(9));
        }];
        //
        self.depositLabel = [[GLGWLabel alloc] initWithFont:SYSTEMFONT(12) theColor:kColor_Rule_Yellow inSuperView:bankgroundView];
        [self.depositLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(bankgroundView.mas_right).offset(-kWidthProportion_In_iPhoneTriploid(15));
            make.top.equalTo(self.goodsLabel.mas_bottom).offset(kHeightProportion_In_iPhoneTriploid(10));
            make.height.equalTo(@(kHeightProportion_In_iPhoneTriploid(17)));
        }];
//        NSString *str = @" 已退定金300元";
//        self.depositLabel.attributedText = [GLGWLabel addImageName:@"iconHome_dingjin" theImageFram:CGRectMake(0, -3, kWidthProportion_In_iPhoneTriploid(15), kHeightProportion_In_iPhoneTriploid(15)) theTextString:str atImageIndex:0];
        
        self.stellOLabel = [[GLGWLabel alloc] initWithFont:SYSTEMFONT(13) theColor:[UIColor colorWithHexString:@"#666666"] inSuperView:bankgroundView];
//        self.stellOLabel.text = @"共4种 安徽 鞍钢/河钢/不限钢厂";
        [self.stellOLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self.depositLabel);
            self.lableTopConstraint = make.top.equalTo(self.depositLabel.mas_bottom).offset(kHeightProportion_In_iPhoneTriploid(10));
            make.height.equalTo(@(kHeightProportion_In_iPhoneTriploid(18)));
        }];
        
        self.baoJiaeLabel = [[GLGWLabel alloc] initWithFont:SYSTEMFONT(12) theColor:[UIColor colorWithHexString:@"#999999"] inSuperView:bankgroundView];
        self.baoJiaeLabel.textAlignment = NSTextAlignmentRight;
        self.baoJiaeLabel.attributedText = [GLGWLabel bllChangeStr:@"11月28日 | 4家已报价 | 1天5小时35分26秒截止" changewithStr:@"1天5小时35分26秒截止" changeColoer:[UIColor colorWithHexString:@"#FF374F"] withFont:SYSTEMFONT(12)];
        [self.baoJiaeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self.stellOLabel);
            make.top.equalTo(self.stellOLabel.mas_bottom).offset(kHeightProportion_In_iPhoneTriploid(12));
            make.height.equalTo(@(kHeightProportion_In_iPhoneTriploid(17)));
            make.bottom.equalTo(bankgroundView.mas_bottom).offset(-kHeightProportion_In_iPhoneTriploid(10));
        }];
    }
    return self;
}

- (void)setFreeDataModel:(HomeFreemanagerpurchaseinfosModel_Data *)freeDataModel
{
    _freeDataModel = freeDataModel;
    NSString *purGoodsStr;
    for (HomeFreemanagerpurchaseinfosModel_PurchaseDetailsVo *purchaseModel in _freeDataModel.purchaseDetailsVo) {
        if (purGoodsStr.length == 0) {
            purGoodsStr = [NSString stringWithFormat:@"%@ %@ %@ %ld吨",koString(purchaseModel.productName),koString(purchaseModel.materialName),koString(purchaseModel.specificationsName),(long)purchaseModel.weight];
        } else {
            purGoodsStr = [NSString stringWithFormat:@"%@ / %@ %@ %@ %ld吨",purGoodsStr,koString(purchaseModel.productName),koString(purchaseModel.materialName),koString(purchaseModel.specificationsName),(long)purchaseModel.weight];
        }
    }
    self.goodsLabel.text = purGoodsStr;
    switch (_freeDataModel.type) {////求购类型//1、普通求购 2、定金求购、3. 图片求购 4 委托求购 5长期求购',
        case 1:{
            self.typeImageView.imageName = @"icon_putongqiugou";
        }
            break;
        case 2:{
            self.typeImageView.imageName = @"icon_dingjinqiugou";
            self.depositLabel.attributedText = [GLGWLabel addImageName:@"iconHome_dingjin" theImageFram:CGRectMake(0, -3, 15, 15) theTextString:@" 已退定金300元" atImageIndex:0];
        }
            break;
        case 4:{
            self.typeImageView.imageName = @"icon_weituoqiugou";
        }
            break;
        case 5:{
            self.typeImageView.imageName = @"icon_changqiqiugou_home";
        }
            break;
            
        default:
            break;
    }
    
    if (_freeDataModel.type != 2) {
        [self.lableTopConstraint uninstall];
        [self.stellOLabel mas_updateConstraints:^(MASConstraintMaker *make) {
            self.lableTopConstraint = make.top.equalTo(self.goodsLabel.mas_bottom).offset(kHeightProportion_In_iPhoneTriploid(10));
        }];
    }else{
        [self.lableTopConstraint uninstall];
        [self.stellOLabel mas_updateConstraints:^(MASConstraintMaker *make) {
            self.lableTopConstraint = make.top.equalTo(self.depositLabel.mas_bottom).offset(kHeightProportion_In_iPhoneTriploid(10));
        }];
    }
    //
    self.stellOLabel.text = @"共4种 安徽 鞍钢/河钢/不限钢厂";
}

- (void)setPurchaseListModel:(PurchaseAllListDataInfosModel *)purchaseListModel
{
    _purchaseListModel = purchaseListModel;
    if (purchaseListModel.type == 1) { // 1、普通求购 2、定金求购、3. 图片求购 4 委托求购 5长期求购'
        self.typeImageView.imageName = @"icon_putongqiugou";
    } else if (purchaseListModel.status == 2) {
        self.typeImageView.imageName = @"icon_dingjinqiugou";
    } else if (purchaseListModel.status == 3) {
        self.typeImageView.imageName = @"icon_tupianqiugou";
    } else if (purchaseListModel.status == 4) {
        self.typeImageView.imageName = @"icon_weituoqiugou";
    } else if (purchaseListModel.status == 5) {
        self.typeImageView.imageName = @"icon_changqiqiugou";
    }
    
    self.goodsLabel.text = purchaseListModel.titleWord;
    if (purchaseListModel.status == 2) { // 定金求购
        NSString *str = [NSString stringWithFormat:@" 已退定金%@元",purchaseListModel.depositAmount];
        self.depositLabel.attributedText = [GLGWLabel addImageName:@"iconHome_dingjin" theImageFram:CGRectMake(0, -3, 15, 15) theTextString:str atImageIndex:0];
    } else {
        [self.lableTopConstraint uninstall];
        [self.stellOLabel mas_updateConstraints:^(MASConstraintMaker *make) {
            self.lableTopConstraint = make.top.equalTo(self.goodsLabel.mas_bottom).offset(kHeightProportion_In_iPhoneTriploid(10));
        }];
    }
    self.stellOLabel.text = purchaseListModel.factoryName;
    NSString *creatTimeStr = [NSString stringWithFormat:@"%@ | ",purchaseListModel.createTime]; // @"11月28日 | 4家已报价 | 1天5小时35分26秒截止"
    NSString *offerStr = [NSString stringWithFormat:@"%@家已报价 | ",purchaseListModel.offerNum];
    NSString *endTimeStr = [NSString stringWithFormat:@""];
    NSString *str6 = [NSString stringWithFormat:@"%@%@%@",creatTimeStr, offerStr,endTimeStr];
    self.baoJiaeLabel.attributedText = [GLGWLabel bllChangeStr:str6 changewithStr:endTimeStr changeColoer:[UIColor colorWithHexString:@"#FF374F"] withFont:SYSTEMFONT(12)];
}
@end
